<template>
  <!-- 顶部栏 -->
  <van-nav-bar title="搜索结果" left-text="返回" placeholder left-arrow fixed @click-left="$router.back()" />
  <!-- 内容 -->
  <div v-for="item in data" :key="item.proid">
    <van-card :price="Math.round(item.originprice * item.discount) / 10" :desc="item.desc" :title="item.proname"
      :thumb="item.banners[0]" :origin-price="item.originprice" @click="onProductClick(item.proid)" />
  </div>
</template>

<script setup>
import { searchReq } from '@/api/home'
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
let router = useRouter()
let route = useRoute()
let data = ref([])
getData()
async function getData() {
  let res = await searchReq(route.query.keyword)
  data.value = res.data.data
}
function onProductClick(productId) {
  router.push('/item?proid=' + productId)
}
</script>

<style></style>
